﻿namespace ACCOUNTING
{
    using System;
    using System.Runtime.CompilerServices;
    using System.Runtime.InteropServices;
    using System.Text;

    public class Win32API
    {
        public const int GW_OWNER = 4;
        public const int GWL_EXSTYLE = -20;
        public const int SW_RESTORE = 9;
        public const int SW_SHOW = 5;
        public const int WS_EX_APPWINDOW = 0x40000;
        public const int WS_EX_TOOLWINDOW = 0x80;

        [DllImport("kernel32", EntryPoint="CreateDirectoryA", CharSet=CharSet.Ansi, SetLastError=true, ExactSpelling=true)]
        public static extern bool CreateDirectory([MarshalAs(UnmanagedType.VBByRefStr)] ref string lpPathName, ref SECURITY_ATTRIBUTES lpSecurityAttributes);
        [DllImport("user32.dll", CharSet=CharSet.Ansi, SetLastError=true, ExactSpelling=true)]
        public static extern int EnumWindows(EnumWindowsCallback callback, int lParam);
        [DllImport("user32.dll", EntryPoint="EnumWindows", CallingConvention=CallingConvention.StdCall, CharSet=CharSet.Ansi, SetLastError=true, ExactSpelling=true)]
        public static extern int EnumWindowsDllImport(EnumWindowsCallback callback, int lParam);
        [DllImport("user32.dll", CharSet=CharSet.Auto, SetLastError=true)]
        public static extern int FindWindow([MarshalAs(UnmanagedType.VBByRefStr)] ref string lpClassName, [MarshalAs(UnmanagedType.VBByRefStr)] ref string lpWindowName);
        [DllImport("user32.dll", EntryPoint="FindWindow", CharSet=CharSet.Auto, SetLastError=true)]
        public static extern int FindWindowAny(int lpClassName, int lpWindowName);
        [DllImport("user32.dll", EntryPoint="FindWindow", CharSet=CharSet.Auto, SetLastError=true)]
        public static extern int FindWindowNullClassName(int lpClassName, [MarshalAs(UnmanagedType.VBByRefStr)] ref string lpWindowName);
        [DllImport("user32.dll", EntryPoint="FindWindow", CharSet=CharSet.Auto, SetLastError=true)]
        public static extern int FindWindowNullWindowCaption([MarshalAs(UnmanagedType.VBByRefStr)] ref string lpClassName, int lpWindowName);
        [DllImport("user32.dll", EntryPoint="GetClassNameA", CharSet=CharSet.Ansi, SetLastError=true, ExactSpelling=true)]
        public static extern int GetClassName(int hwnd, StringBuilder lpClassName, int cch);
        [DllImport("kernel32", EntryPoint="GetDiskFreeSpaceA", CharSet=CharSet.Ansi, SetLastError=true, ExactSpelling=true)]
        public static extern int GetDiskFreeSpace([MarshalAs(UnmanagedType.VBByRefStr)] ref string lpRootPathName, ref int lpSectorsPerCluster, ref int lpBytesPerSector, ref int lpNumberOfFreeClusters, ref int lpTotalNumberOfClusters);
        [DllImport("kernel32", EntryPoint="GetDiskFreeSpaceExA", CharSet=CharSet.Ansi, SetLastError=true, ExactSpelling=true)]
        public static extern int GetDiskFreeSpaceEx([MarshalAs(UnmanagedType.VBByRefStr)] ref string lpRootPathName, ref int lpFreeBytesAvailableToCaller, ref int lpTotalNumberOfBytes, ref uint lpTotalNumberOfFreeBytes);
        [DllImport("kernel32", EntryPoint="GetDriveTypeA", CharSet=CharSet.Ansi, SetLastError=true, ExactSpelling=true)]
        public static extern int GetDriveType([MarshalAs(UnmanagedType.VBByRefStr)] ref string nDrive);
        [DllImport("user32.dll", CharSet=CharSet.Ansi, SetLastError=true, ExactSpelling=true)]
        public static extern int GetParent(int hwnd);
        [DllImport("kernel32.dll", EntryPoint="GetVersionExA", CharSet=CharSet.Ansi, SetLastError=true, ExactSpelling=true)]
        public static extern bool GetVersionEx(ref OSVersionInfo osvi);
        [DllImport("user32.dll", CharSet=CharSet.Ansi, SetLastError=true, ExactSpelling=true)]
        public static extern int GetWindow(int hwnd, int wCmd);
        [DllImport("user32.dll", EntryPoint="GetWindowLongA", CharSet=CharSet.Ansi, SetLastError=true, ExactSpelling=true)]
        public static extern int GetWindowLong(int hwnd, int nIndex);
        [DllImport("user32.dll", EntryPoint="GetWindowTextA", CharSet=CharSet.Ansi, SetLastError=true, ExactSpelling=true)]
        public static extern void GetWindowText(int hWnd, StringBuilder lpString, int nMaxCount);
        [DllImport("user32.dll", CharSet=CharSet.Ansi, SetLastError=true, ExactSpelling=true)]
        public static extern bool IsIconic(int hwnd);
        [DllImport("Powrprof.dll", CharSet=CharSet.Ansi, SetLastError=true, ExactSpelling=true)]
        public static extern int IsPwrHibernateAllowed();
        [DllImport("user32.dll", CharSet=CharSet.Ansi, SetLastError=true, ExactSpelling=true)]
        public static extern bool IsWindowVisible(int hwnd);
        [DllImport("advapi32.dll", CharSet=CharSet.Ansi, SetLastError=true, ExactSpelling=true)]
        public static extern long RegCloseKey(long hKey);
        [DllImport("advapi32.dll", EntryPoint="RegCreateKeyA", CharSet=CharSet.Ansi, SetLastError=true, ExactSpelling=true)]
        public static extern long RegCreateKey(long hKey, [MarshalAs(UnmanagedType.VBByRefStr)] ref string lpSubKey, long phkResult);
        [DllImport("advapi32.dll", EntryPoint="RegDeleteValueA", CharSet=CharSet.Ansi, SetLastError=true, ExactSpelling=true)]
        public static extern long RegDeleteValue(long hKey, [MarshalAs(UnmanagedType.VBByRefStr)] ref string lpValueName);
        [DllImport("advapi32.dll", EntryPoint="RegOpenKeyA", CharSet=CharSet.Ansi, SetLastError=true, ExactSpelling=true)]
        public static extern long RegOpenKey(long hKey, [MarshalAs(UnmanagedType.VBByRefStr)] ref string lpSubKey, long phkResult);
        public string RegQueryStringValue(long hKey, string strValueName)
        {
            long num=0;
            long num3=0;
            string str=String.Empty;
            long num2 = RegQueryValueEx(hKey, ref strValueName, 0L, num3, 0, num);
            return str;
        }

        [DllImport("advapi32.dll", EntryPoint="RegQueryValueExA", CharSet=CharSet.Ansi, SetLastError=true, ExactSpelling=true)]
        public static extern long RegQueryValueEx(long hKey, [MarshalAs(UnmanagedType.VBByRefStr)] ref string lpValueName, long lpReserved, long lpType, object lpData, long lpcbData);
        [DllImport("advapi32.dll", EntryPoint="RegSetValueExA", CharSet=CharSet.Ansi, SetLastError=true, ExactSpelling=true)]
        public static extern long RegSetValueEx(long hKey, [MarshalAs(UnmanagedType.VBByRefStr)] ref string lpValueName, long reserved, long dwType, object lpData, long cbData);
        [DllImport("user32.dll", CharSet=CharSet.Ansi, SetLastError=true, ExactSpelling=true)]
        public static extern int SetForegroundWindow(int hwnd);
        [DllImport("Powrprof.dll", CharSet=CharSet.Ansi, SetLastError=true, ExactSpelling=true)]
        public static extern int SetSuspendState(int Hibernate, int ForceCritical, int DisableWakeEvent);
        [DllImport("user32.dll", CharSet=CharSet.Ansi, SetLastError=true, ExactSpelling=true)]
        public static extern int ShowWindow(int hwnd, int nCmdShow);
        [DllImport("user32.dll", CharSet=CharSet.Ansi, SetLastError=true, ExactSpelling=true)]
        public static extern int SwapMouseButton(int bSwap);

        public delegate bool EnumWindowsCallback(int hWnd, int lParam);

        [StructLayout(LayoutKind.Sequential)]
        public struct OSVersionInfo
        {
            public int OSVersionInfoSize;
            public int majorVersion;
            public int minorVersion;
            public int buildNumber;
            public int platformId;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst=0x80)]
            public string versionString;
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct SECURITY_ATTRIBUTES
        {
            public int nLength;
            public int lpSecurityDescriptor;
            public int bInheritHandle;
        }
    }
}

